package com.system.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.auth.domain.T_function;
import com.auth.domain.T_role;
import com.auth.domain.T_role_function;
import com.auth.domain.T_user;
import com.auth.domain.T_user_function;
import com.auth.domain.T_user_role;
import com.auth.mapper.T_functionMapper;
import com.auth.mapper.T_roleMapper;
import com.auth.mapper.T_role_functionMapper;
import com.auth.mapper.T_userMapper;
import com.auth.mapper.T_user_functionMapper;
import com.auth.mapper.T_user_roleMapper;
import com.system.domain.T_data_dic;
import com.system.domain.T_login_log;
import com.system.mapper.T_data_dicMapper;
import com.system.mapper.T_login_logMapper;

@Service
@Transactional
public class LogonService {
	private static Logger log = Logger.getLogger(LogonService.class.getName());

	@Resource
	private T_data_dicMapper dataDicMapper;
	@Resource
	private T_roleMapper roleMapper;
	@Resource
	private T_userMapper mapper;
	@Resource
	private T_functionMapper functionMapper;
	@Resource
	private T_user_roleMapper userRoleMapper;
	@Resource
	private T_role_functionMapper roleFunctionMapper;
	@Resource
	private T_user_functionMapper userFunctionMapper;
	@Resource
	private T_login_logMapper loginlogMapper;

	public int saveLoginlog(T_login_log obj){
		return  loginlogMapper.save(obj);
	}

	public List findByDataNo(T_data_dic obj){
		return dataDicMapper.findByDataNo(obj);
	}

	public List findAllUser(T_user obj){
		return mapper.findAll(obj);
	}

	public List findAllFunction(T_function obj){
		return functionMapper.findAll(obj);
	}

	public List findAllRole(T_role obj){
		return roleMapper.findAll(obj);
	}

	public List findAllUserRole(T_user_role obj){
		return userRoleMapper.findAll(obj);
	}

	public List findAllRoleFunction(T_role_function obj){
		return roleFunctionMapper.findAll(obj);
	}

	public List findAllUserFunction(T_user_function obj){
		return userFunctionMapper.findAll(obj);
	}



	/*
	 * 测试事务是否一致，是否在一个事务中，下面2个save有一个会报运行时错误，应该2条数据都不能插入数据库，就是事务控制回滚成功，否则失败；
	 */
	public int saveLoginlog(T_login_log obj1, T_login_log obj2){
		  loginlogMapper.save(obj1);
		  loginlogMapper.save(obj2);
		  return 0;
	}

}
